package com.lb.shopguide.ui.activity;

import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.lb.shopguide.R;
import com.lb.shopguide.base.BaseActivity;

import java.util.Stack;

/**
 * Create by kangzhao on 2018/12/19
 */
public class ActivityRecommendGuide extends BaseActivity {
    private ImageView ivGuide;
    private TextView tvSkip;


    private Stack<Integer> stackImag;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recommend_guide);

        initData();
        initView();
        initListener();
    }

    private void initData() {
        stackImag = new Stack<>();
        stackImag.push(R.drawable.image_guide_view_1);
        stackImag.push(R.drawable.image_guide_view_5);
        stackImag.push(R.drawable.image_guide_view_4);
        stackImag.push(R.drawable.image_guide_view_3);
        stackImag.push(R.drawable.image_guide_view_2);
    }

    private void initView() {
        ivGuide = findViewById(R.id.iv_guide);
        tvSkip = findViewById(R.id.tv_jump);
        changeImage();
        tvSkip.setVisibility(View.VISIBLE);
    }

    private void initListener() {
        ivGuide.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                changeImage();
            }
        });
        tvSkip.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private void changeImage() {
        if (stackImag.size() != 0) {
            ivGuide.setImageResource(stackImag.pop());
            tvSkip.setVisibility(View.GONE);
        } else {
            finish();
        }
    }


    @Override
    public void onBackPressedSupport() {
        if (stackImag.size() != 0) {
            changeImage();
        } else {
            finish();
        }
    }

}
